-- recover_summon
-- created by panyl
-- 进入下层恢复召唤兽血量N%

return {
    apply = function(prop, baseValue)
        return FormulaM.invoke("CALC_BIG_DIVISION", baseValue, prop[3], 1000);
    end,

    -- 进入下层触发触发
    trigger = function(who, prop, arg)
        local summonRule = prop[2];

        local summonInfo = who.dbase:query("summon");
        -- 当前没有召唤兽
        if not summonInfo then
            return;
        end

        for pos, data in pairs(summonInfo) do
            -- 如果是目标召唤兽
            local classId = data["class_id"];
            local grid = DungeonM.getGridByPos(pos);
            local summon = grid.summon;
            if SummonM.query(classId, "rule") == summonRule and summon and not summon:isDead() then
                local summonHp = summon:queryAttrib("max_hp");
                local addHp = FormulaM.invoke("CALC_BIG_DIVISION", summonHp, prop[3], 1000);
                summon:addAttrib("hp", addHp);
            end
        end

        return prop[3];
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        desc = string.gsub(desc, "{1}", math.modf(prop[3] / 10));

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};
